package com.xiaoying.server.publish.entity;

import java.io.File;
import java.io.Serializable;

import com.xiaoying.server.publish.utils.DateUtil;
import com.xiaoying.server.publish.utils.RandomUtil;

public class FileInfo implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int id;
	private String fileName;
	private String filePath;	
	private long fileSize;		//单位KB
	private String fileSuffix;
	private short fileType;		//fileType:3=video 4=Image cover  5=image poster
	private int uploadCount;	//上传的次数
	private String receiveDt;	//文件接收的时间
	
	// default constructor
	public FileInfo() {
		
	}
	
	// full constructor 
	public FileInfo(File file,int id,short fileType) {
        this.filePath = file.getAbsolutePath();
        this.fileSize = file.length()>>10;    
        if(file.getName()!=null&& file.getName().length()>0){
            int dot = file.getName().lastIndexOf('.');
            if(dot>0 && dot<(file.getName().length()-1)){
            	this.fileName = file.getName().substring(0, dot);
                this.fileSuffix = file.getName().substring(dot);
            }
        }        
        this.id = id;
        this.fileType = fileType;
        this.uploadCount = 0;
        this.fileName=this.fileType+"_"+DateUtil.getCurrentDateTimeByFormat2()+RandomUtil.getRamdomCharacter(4);
    }
	
	// constructor with fileType 
	public FileInfo(File file,short fileType) {
        this.filePath = file.getAbsolutePath();
        this.fileSize = file.length()>>10;
        if(file.getName()!=null&& file.getName().length()>0){
            int dot = file.getName().lastIndexOf('.');
            if(dot>0 && dot<(file.getName().length()-1)){
            	this.fileName = file.getName().substring(0, dot-1);
                this.fileSuffix = file.getName().substring(dot);
            }
        }            
        this.fileType = fileType;
        this.uploadCount = 0;
        this.fileName=this.fileType+"_"+DateUtil.getCurrentDateTimeByFormat2()+RandomUtil.getRamdomCharacter(4);
    }
	
	// mini constructor
	public FileInfo(File file,int id) {
        this.filePath = file.getAbsolutePath();
        this.fileSize = file.length()>>10;
        
        if(file.getName()!=null&& file.getName().length()>0){
            int dot = file.getName().lastIndexOf('.');
            if(dot>0 && dot<(file.getName().length()-1)){
            	this.fileName = file.getName().substring(0, dot-1);
                this.fileSuffix = file.getName().substring(dot);
            }
        }
        this.id = id;
        this.uploadCount = 0;
        this.fileName=this.fileType+"_"+DateUtil.getCurrentDateTimeByFormat2()+RandomUtil.getRamdomCharacter(4);
    }
	
	// mini constructor
	public FileInfo(File file) {
		this.filePath = file.getAbsolutePath();
		this.fileSize = file.length()>>10;
		
        if(this.fileName!=null&& this.fileName.length()>0){
            int dot = file.getName().lastIndexOf('.');
            if(dot>0 && dot<(file.getName().length()-1)){
            	this.fileName = file.getName().substring(0, dot-1);
                this.fileSuffix = file.getName().substring(dot);
            }
        }
		this.uploadCount = 0;
		this.fileName=this.fileType+"_"+DateUtil.getCurrentDateTimeByFormat2()+RandomUtil.getRamdomCharacter(4);
	}
	
	public FileInfo(int id, String fileName, String filePath, long fileSize,
			String fileSuffix, short fileType, int uploadCount, String receiveDt) {
		this.id = id;
		this.fileName = fileName;
		this.filePath = filePath;
		this.fileSize = fileSize;
		this.fileSuffix = fileSuffix;
		this.fileType = fileType;
		this.uploadCount = uploadCount;
		this.receiveDt = receiveDt;
	}

	public String getFileName() {
		return fileName;
	}
	
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	public long getFileSize() {
		return fileSize;
	}
	
	public void setFileSize(long fileSize) {
		this.fileSize = fileSize;
	}

	public String getFileSuffix() {
		return fileSuffix;
	}

	public void setFileSuffix(String fileSuffix) {
		this.fileSuffix = fileSuffix;
	}

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

	public short getFileType() {
		return fileType;
	}

	public void setFileType(short fileType) {
		this.fileType = fileType;
	}

	public int getUploadCount() {
		return uploadCount;
	}

	public void setUploadCount(int uploadCount) {
		this.uploadCount = uploadCount;
	}

	public String getReceiveDt() {
		return receiveDt;
	}

	public void setReceiveDt(String receiveDt) {
		this.receiveDt = receiveDt;
	}		
	
}
